package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.TbTest;
import com.ruoyi.system.service.ITbTestService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: zhoupeng
 * @date: 2021/9/16 0:04
 * @descreption: 波形图查看控制层
 */
@Controller
@RequestMapping("/system/waveform")
public class WaveformController extends BaseController {

    private String prefix = "system/waveform";

    @Resource
    private ITbTestService tbTestService;

    @RequiresPermissions("system:waveform:view")
    @GetMapping()
    public String waveform() {
        return prefix + "/waveform";
    }

    /**
     * 查询列表
     */
    @RequiresPermissions("system:waveform:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbTest tbTest) {
        startPage();
        List<TbTest> list = tbTestService.selectTbTestList(tbTest);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
    @RequiresPermissions("system:waveform:export")
    @Log(title = "导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbTest tbTest) {
        List<TbTest> list = tbTestService.selectTbTestList(tbTest);
        ExcelUtil<TbTest> util = new ExcelUtil<>(TbTest.class);
        return util.exportExcel(list, "导出数据");
    }

    /**
     * 新增
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存
     */
    @RequiresPermissions("system:waveform:add")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbTest tbTest) {
        return toAjax(tbTestService.insertTbTest(tbTest));
    }

    /**
     * 修改
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        TbTest tbTest = tbTestService.selectTbTestById(id);
        mmap.put("tbTest", tbTest);
        return "system/waveform/edit";
    }

    /**
     * 修改保存
     */
    @RequiresPermissions("system:waveform:edit")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbTest tbTest) {
        return toAjax(tbTestService.updateTbTest(tbTest));
    }

    /**
     * 删除
     */
    @RequiresPermissions("system:waveform:remove")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(tbTestService.deleteTbTestByIds(ids));
    }
}
